<?php

@$id = $_REQUEST["id"];


$name = $_REQUEST["name"];





function add($name)
{

    $pdo = new PDO("mysql:dbname=caipin;host=127.0.0.1;charset=utf8", "root", "root");
    $cpSql = $pdo->prepare("insert into caixi(caixiname) values(:n);");

    $isok = $cpSql->execute(array("n" => $name));
    if ($isok) {
        echo "添加成功！";
    } else {
        echo "添加失败！";
    }
}

function update($id, $name)
{
  

    $pdo = new PDO("mysql:dbname=caipin;host=127.0.0.1;charset=utf8", "root", "root");

    $sql = $pdo->prepare("select * from caixi where id=:id");
    $sql->execute(array("id" => $id));
    $jg = $sql->fetch(PDO::FETCH_NAMED);
    if (!empty($jg)) {
        $usql = $pdo->prepare("update caixi set caixiname=:n where id=:id;");
		  header("Refresh:3;url=cailiexingliebiao.php");
        $isok = $usql->execute(array("n" => $name , "id" => $id));
        if ($isok) {
            echo "修改成功！";
        } else {
            echo "修改失败！";
        }
    }

}

if (empty($id)) {
    add($name);
} else {
    update($id, $name);
}
